using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;


namespace OpenProject.DataObjects{
    /// <summary>
    /// Strongly-typed collection for the Project class.
    /// </summary>
    [Serializable]
    public partial class ProjectCollection : ActiveList<Project, ProjectCollection> 
    {       
        public ProjectCollection() {}

    }

    /// <summary>
    /// This is an ActiveRecord class which wraps the Project table.
    /// </summary>
    [Serializable]
    public partial class Project : ActiveRecord<Project>
    {
    
	    #region Default Settings
	    protected static void SetSQLProps() 
	    {
		    GetTableSchema();
	    }

	    #endregion
        #region Schema Accessor
	    public static TableSchema.Table Schema
        {
            get
            {
                if (BaseSchema == null)
                {
                    SetSQLProps();
                }

                return BaseSchema;
            }

        }

    	
        private static void GetTableSchema() 
	    {
            if(!IsSchemaInitialized)
            {
                //Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Project", TableType.Table, DataService.GetInstance("OpenProject"));
                schema.Columns = new TableSchema.TableColumnCollection();
                schema.SchemaName = @"dbo";
                //columns
                
                TableSchema.TableColumn colvarProjectId = new TableSchema.TableColumn(schema);
                colvarProjectId.ColumnName = "ProjectId";
                colvarProjectId.DataType = DbType.Int32;
                colvarProjectId.MaxLength = 0;
                colvarProjectId.AutoIncrement = true;
                colvarProjectId.IsNullable = false;
                colvarProjectId.IsPrimaryKey = true;
                colvarProjectId.IsForeignKey = false;
                colvarProjectId.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarProjectId);
                
                TableSchema.TableColumn colvarProjectCode = new TableSchema.TableColumn(schema);
                colvarProjectCode.ColumnName = "ProjectCode";
                colvarProjectCode.DataType = DbType.String;
                colvarProjectCode.MaxLength = 50;
                colvarProjectCode.AutoIncrement = false;
                colvarProjectCode.IsNullable = true;
                colvarProjectCode.IsPrimaryKey = false;
                colvarProjectCode.IsForeignKey = false;
                colvarProjectCode.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarProjectCode);
                
                TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
                colvarTitle.ColumnName = "Title";
                colvarTitle.DataType = DbType.String;
                colvarTitle.MaxLength = 100;
                colvarTitle.AutoIncrement = false;
                colvarTitle.IsNullable = false;
                colvarTitle.IsPrimaryKey = false;
                colvarTitle.IsForeignKey = false;
                colvarTitle.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarTitle);
                
                TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
                colvarDescription.ColumnName = "Description";
                colvarDescription.DataType = DbType.String;
                colvarDescription.MaxLength = 500;
                colvarDescription.AutoIncrement = false;
                colvarDescription.IsNullable = true;
                colvarDescription.IsPrimaryKey = false;
                colvarDescription.IsForeignKey = false;
                colvarDescription.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarDescription);
                
                TableSchema.TableColumn colvarIsActive = new TableSchema.TableColumn(schema);
                colvarIsActive.ColumnName = "IsActive";
                colvarIsActive.DataType = DbType.Boolean;
                colvarIsActive.MaxLength = 0;
                colvarIsActive.AutoIncrement = false;
                colvarIsActive.IsNullable = true;
                colvarIsActive.IsPrimaryKey = false;
                colvarIsActive.IsForeignKey = false;
                colvarIsActive.IsReadOnly = false;
                
						colvarIsActive.DefaultSetting = @"((1))";
				
                
                schema.Columns.Add(colvarIsActive);
                
                TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
                colvarCreatedOn.ColumnName = "CreatedOn";
                colvarCreatedOn.DataType = DbType.DateTime;
                colvarCreatedOn.MaxLength = 0;
                colvarCreatedOn.AutoIncrement = false;
                colvarCreatedOn.IsNullable = true;
                colvarCreatedOn.IsPrimaryKey = false;
                colvarCreatedOn.IsForeignKey = false;
                colvarCreatedOn.IsReadOnly = false;
                
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				
                
                schema.Columns.Add(colvarCreatedOn);
                
                BaseSchema = schema;
                //add this schema to the provider
                //so we can query it later
                DataService.Providers["OpenProject"].AddSchema("Project",schema);
            }

        }

        #endregion
        
        #region Query Accessor
	    public static Query CreateQuery()
	    {
		    return new Query(Schema);
	    }

	    #endregion
	    
	    #region .ctors
	    public Project()
	    {
            SetSQLProps();
            SetDefaults();
            MarkNew();
        }

        
        public Project(bool useDatabaseDefaults)
	    {
		    SetSQLProps();
		    if(useDatabaseDefaults)
		    {
				ForceDefaults();
			}

			MarkNew();
	    }

	    public Project(object keyID)
	    {
		    SetSQLProps();
            SetDefaults();
		    LoadByKey(keyID);
	    }

    	 
	    public Project(string columnName, object columnValue)
        {
            SetSQLProps();
            SetDefaults();
            LoadByParam(columnName,columnValue);
        }

        
	    #endregion
	    
	    #region Props
	    
          
        [XmlAttribute("ProjectId")]
        public int ProjectId 
	    {
		    get { return GetColumnValue<int>("ProjectId"); }

            set 
		    {
			    SetColumnValue("ProjectId", value);
            }

        }

	      
        [XmlAttribute("ProjectCode")]
        public string ProjectCode 
	    {
		    get { return GetColumnValue<string>("ProjectCode"); }

            set 
		    {
			    SetColumnValue("ProjectCode", value);
            }

        }

	      
        [XmlAttribute("Title")]
        public string Title 
	    {
		    get { return GetColumnValue<string>("Title"); }

            set 
		    {
			    SetColumnValue("Title", value);
            }

        }

	      
        [XmlAttribute("Description")]
        public string Description 
	    {
		    get { return GetColumnValue<string>("Description"); }

            set 
		    {
			    SetColumnValue("Description", value);
            }

        }

	      
        [XmlAttribute("IsActive")]
        public bool? IsActive 
	    {
		    get { return GetColumnValue<bool?>("IsActive"); }

            set 
		    {
			    SetColumnValue("IsActive", value);
            }

        }

	      
        [XmlAttribute("CreatedOn")]
        public DateTime? CreatedOn 
	    {
		    get { return GetColumnValue<DateTime?>("CreatedOn"); }

            set 
		    {
			    SetColumnValue("CreatedOn", value);
            }

        }

	    
	    #endregion
	    
	    
	    #region PrimaryKey Methods
	    
		public OpenProject.DataObjects.CMSPageCollection CMSPageRecords
		{
			get
			{
				return new OpenProject.DataObjects.CMSPageCollection().Where(CMSPage.Columns.ProjectId, ProjectId).Load();
			}

		}

		public OpenProject.DataObjects.PhaseCollection PhaseRecords
		{
			get
			{
				return new OpenProject.DataObjects.PhaseCollection().Where(Phase.Columns.ProjectId, ProjectId).Load();
			}

		}

		public OpenProject.DataObjects.WorkItemCollection WorkItemRecords
		{
			get
			{
				return new OpenProject.DataObjects.WorkItemCollection().Where(WorkItem.Columns.ProjectId, ProjectId).Load();
			}

		}

		#endregion
		
	 	
			
	    
	    //no foreign key tables defined (0)
	    
	    
	    
	    //no ManyToMany tables defined (0)
	    
	    #region ObjectDataSource support
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
	    public static void Insert(string varProjectCode,string varTitle,string varDescription,bool? varIsActive,DateTime? varCreatedOn)
	    {
		    Project item = new Project();
		    
            item.ProjectCode = varProjectCode;
            
            item.Title = varTitle;
            
            item.Description = varDescription;
            
            item.IsActive = varIsActive;
            
            item.CreatedOn = varCreatedOn;
            
	    
		    if (System.Web.HttpContext.Current != null)
			    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
		    else
			    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
	    public static void Update(int varProjectId,string varProjectCode,string varTitle,string varDescription,bool? varIsActive,DateTime? varCreatedOn)
	    {
		    Project item = new Project();
		    
                item.ProjectId = varProjectId;
				
                item.ProjectCode = varProjectCode;
				
                item.Title = varTitle;
				
                item.Description = varDescription;
				
                item.IsActive = varIsActive;
				
                item.CreatedOn = varCreatedOn;
				
		    item.IsNew = false;
		    if (System.Web.HttpContext.Current != null)
			    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
		    else
			    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
	    }

	    #endregion
	    #region Columns Struct
	    public struct Columns
	    {
		    
		    
            public static string ProjectId = @"ProjectId";
            
            public static string ProjectCode = @"ProjectCode";
            
            public static string Title = @"Title";
            
            public static string Description = @"Description";
            
            public static string IsActive = @"IsActive";
            
            public static string CreatedOn = @"CreatedOn";
            
	    }

	    #endregion
    }

}

